package rock.loadbalance.impl;

import rock.loadbalance.AbstractLoadBalance;
import rock.remoting.dto.RpcRequest;

import java.util.List;
import java.util.Random;

/**
 * 随机负载均衡
 */
public class RandomLoadBalance extends AbstractLoadBalance {
    /**
     * 使用Random类
     * @param serviceAddresses 可选list
     * @param request rpc request
     * @return
     */
    @Override
    protected String doSelect(List<String> serviceAddresses, RpcRequest request) {
        Random rand = new Random();
        return serviceAddresses.get(rand.nextInt(serviceAddresses.size()));
    }
}
